import java.util.*;

/**
 * Describes zero, one or more accounts.
 * 
 * @author Fredrik Gustafsson och Viktor Holmberg
 */
public class ATMAccounts {
	private Hashtable<Integer, ATMAccount>	accounts;
	private static ATMAccounts				accObject	= null;

	/**
	 * Constructor, starts a new hastable containing accounts.
	 */
	public ATMAccounts() {
		this.accounts = new Hashtable<Integer, ATMAccount>();
	}

	/**
	 * Simulates a "static" class. Only one can exist.
	 * 
	 * @return the "static" class.
	 */
	public static ATMAccounts getATMAccounts() {
		if (accObject == null) {
			accObject = new ATMAccounts();
		}
		return accObject;
	}

	/**
	 * Retrieve an account.
	 * 
	 * @param accountNumber the account number of the account to retrieve.
	 * @return The account.
	 */
	public ATMAccount getAccount(Integer accountNumber) {
		if (accounts.containsKey(accountNumber))
			return accounts.get(accountNumber);
		else {
			ATMAccount a = new ATMAccount(accountNumber, 0);
			accounts.put(accountNumber, a);
			return a;
		}
	}
}
